package com.example.pengxiangedupay.controller;

import com.alibaba.fastjson.JSON;
import com.example.pengxiangedupay.common.utils.R;
import com.example.pengxiangedupay.service.FeeStuPaidService;
import com.example.pengxiangedupay.service.PaySysUserService;
import com.example.pengxiangedupay.vo.FeeItemDetailVo;
import com.example.pengxiangedupay.vo.FeeItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("info")
public class InfoController {


    @Autowired
    FeeStuPaidService feeStuPaidService;
    @Autowired
    PaySysUserService paySysUserService;

    //查询当前学生对应的款项
    //查询已缴清费用
    @GetMapping("/getPaidInfo")
    public R getFeePaidInfo(Long studentId){
        //查询feeStudentPaid
        List<FeeItemVo> feeItemVos =  feeStuPaidService.getFeePaidInfo(studentId);
        //返回一个feeItemVo的list
        return R.ok().put("data",feeItemVos);
    }
    //查询未缴
    @GetMapping("/getFeeNotPayInfo")
    public R getFeeNotPayInfo(Long studentId){

         //查询feeStudentPaid
        List<FeeItemVo> feeItemVos =  feeStuPaidService.getFeeNotPayInfo(studentId);
        //返回一个feeItemVo的list
        return R.ok().put("data",feeItemVos);
    }
    //查询除当前费用外其他未交的费用
    @GetMapping("/getOtherFeeNotPaid")
    public R getOtherFeeNotPaid(Long studentId,Long feeId){
        //查询feeStudentPaid
        List<FeeItemVo> feeItemVos =  feeStuPaidService.getFeeNotPayInfo(studentId);
        List<FeeItemVo> result = feeItemVos.stream().filter(item -> item.getFeeId() != feeId).collect(Collectors.toList());
        //返回一个feeItemVo的list
        return R.ok().put("data",result);
    }

    //查询学费细节
    @GetMapping("/getFeeDetail")
    public R getFeeDetail(Long feeId) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
        //根据feeId，
        //
        //1.查询 学费类型，减免类型
        //2.查询 原费用、应缴、已缴信息
        //3.查询缴费状态
        //4.查询有无其他未缴纳项

        FeeItemDetailVo feeDetailVo =  feeStuPaidService.getFeeDetail(feeId);
        Object feeDetailJson = JSON.toJSON(feeDetailVo);
        //返回feeDetailVo
        return R.ok().put("data",feeDetailJson);
    }

}
